//缓存写入处理器
// middleware/cacheWriter.js
module.exports = (req, res, next) => {
    const originalSend = res.send;
    
    res.send = async (body) => {
      if (res.statusCode === 200 && res.locals.cacheKey) {
        await redis.setex(
          res.locals.cacheKey, 
          3600, // 1小时过期
          JSON.stringify(body)
        );
      }
      originalSend.call(res, body);
    };
    
    next();
  };